package cn.hywx.convert.tests;

import java.io.File;

import junit.framework.Assert;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import cn.hywx.convert.Convert;

public class ConvertTest{
	private static Convert converter;
	private String sourceUrl = "/home/all3n/convert/2.txt";
	private String pdfFileName = "/home/all3n/convert/2.pdf";
	private String swfFileName = "/home/all3n/convert/2.swf";
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ConvertTest.converter = new Convert();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		ConvertTest.converter.stopService();
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {

	}

	@Test
	public void testOffice2Pdf() {
		File targetFile = new File(pdfFileName);
		if(targetFile.exists()){
			targetFile.delete();
		}
		try {
			ConvertTest.converter.office2Pdf(sourceUrl, pdfFileName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Assert.assertTrue("pdf not gernerate!",targetFile.exists());
	}

	@Test
	public void testPdf2Swf() {
		File swfFile = new File(swfFileName);
		if(swfFile.exists()){
			swfFile.delete();
		}
		converter.pdf2Swf(pdfFileName, swfFileName);
		Assert.assertTrue("swf not gernerate!",swfFile.exists());
	}

}
